//
//  DateViewController.m
//  GCD
//
//  Created by fangyuan ding on 2020/8/11.
//  Copyright © 2020 fangyuan ding. All rights reserved.
//

#import "DateViewController.h"

@interface DateViewController ()

@end

@implementation DateViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSString *timeStr = @"2015-04-10";
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    formatter.dateFormat = @"yyyy-MM-dd";
    formatter.timeZone  = [NSTimeZone defaultTimeZone];
    NSDate *date = [formatter dateFromString:timeStr];
    NSLog(@"%@",date);
}

//递归删除指定路径下的所有文件
+ (void)deleteFiles:(NSString *)path{
    //判断文件还是目录
    NSFileManager *fileManager = [NSFileManager defaultManager];
    BOOL isDir = NO;
    BOOL isExist = [fileManager fileExistsAtPath:path isDirectory:&isDir];
    //判断是不是目录
    if(isExist){
        if(isDir){
            NSArray *dirArray = [fileManager contentsOfDirectoryAtPath:path error:nil];
            NSString *subPath = nil;
            for(NSString *str in dirArray){
                subPath = [path stringByAppendingPathComponent:str];
                BOOL issubDir = NO;
                [fileManager fileExistsAtPath:subPath isDirectory:&issubDir];
                [self deleteFiles:subPath];
            }
            
        }else{
            NSLog(@"%@",path);
            [fileManager removeItemAtPath:path error:nil];
        }
    }else{
        NSLog(@"你打印的是目录或者不存在");
    }
}


@end
